package com.gang.blog.service.impl;

import javax.annotation.Resource;
import org.springframework.stereotype.Service;

import com.gang.blog.dao.UserExpandMapper;
import com.gang.blog.dao.UserMapper;
import com.gang.blog.domain.User;
import com.gang.blog.domain.UserExpand;
import com.gang.blog.service.UserService;

@Service("userServiceImpl")
public class UserServiceImpl implements UserService {
	
	@Resource(name="userMapper")
	private UserMapper userMapper;
	public void setUserMapper(UserMapper userMapper) {
		this.userMapper = userMapper;
	}
	@Resource
	private UserExpandMapper userExpandMapper;
	public void setUserExpandMapper(UserExpandMapper userExpandMapper) {
		this.userExpandMapper = userExpandMapper;
	}

	public boolean addUser(User user) {
		// TODO Auto-generated method stub
		int count = userMapper.insert(user);
		if(count>0){
			return true;
		}
		
		return false;
	}
	
	//anID查找
	public User getUserById(Integer id) {
		return this.userMapper.selectByPrimaryKey(id);
	}
	
	//验证登录
	public User checkLogin(User user) {
		User u = this.userMapper.selectByUserName(user.getUserName());
		//判断登录密码是否符合
		if(u!=null){
			if(u.getUserPassword().equals(user.getUserPassword())){
				return u;
			}else{
				u = null;
				return u;
			}
		}else{
			u = null;
			return u;
		}
	}

	//验证用户名是否可用
	public User checkUserName(String userName) {
		
			//按用户名查找用户对象
			User user = this.userMapper.selectByUserName(userName);
			//如果查到用户返回false，表示名字不可用
			
		return user;
	}

	//插入用户扩展信息
	public Integer insertUserExpand(UserExpand userExpand) {
		Integer count = this.userExpandMapper.insertSelective(userExpand);
		return count;
	}
	//查询用户的拓展信息
	public UserExpand getUserExpand(Integer userId) {
		UserExpand userExpand = this.userExpandMapper.selectByUserId(userId);
		return userExpand;
	}

	public int updateById(User user) {
		
		return this.userMapper.updateByPrimaryKeySelective(user);
	}


	
	
	

	
	
	
}
